#include "ui_cpu.h"

void lv_event_exit_cpu_cb_t(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e); // 获取事件类型
    if (code == LV_EVENT_CLICKED) { // 如果是点击事件
        if (cont != NULL) {
            lv_obj_del(cont);
            cont = NULL;
        }
        printf("Exit CPU UI!\n");
        menu = MENU_HOME;
    }
}

void cpu_show(void)
{
    printf("goto CPU UI!\n");

    if (cont != NULL) {
        printf("%s err\n", __func__);
        cont = NULL;
    }

    cont = lv_obj_create(lv_scr_act()); // 创建容器
    lv_obj_set_size(cont, LCD_H, LCD_W); // 设置容器大小

    lv_obj_t* btn2 = lv_btn_create(cont);
    lv_obj_set_grid_cell(btn2, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, 0, 1); // 放置到第 1 行第 2 列
    lv_obj_t* lb_btn2 = lv_label_create(btn2);
    lv_obj_align(lb_btn2, LV_ALIGN_CENTER, 0, 0);
    lv_label_set_text(lb_btn2, "This is CPU btn! click exit ...");
    lv_obj_add_event_cb(btn2, lv_event_exit_cpu_cb_t, LV_EVENT_ALL, NULL);

}
